package com.example.ui.contact;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.example.huashangapp.HSApplication;
import com.example.huashangapp.R;
import com.example.ui.contact.adapter.CommentAdapter;
import com.example.ui.contact.bean.CommentItem;
import com.example.ui.contact.bean.MeItem;
import com.example.ui.contact.chat.PushMessageReceiver;
import com.example.ui.contact.chat.PushMessageReceiver.EventHandler;
import com.example.ui.contact.db.CommentMsgDB;
import com.example.ui.leftmenu.Item07View;
import com.example.util.BitmapLoad;
import com.example.util.Util;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

public class CommentMeActivity extends Activity implements EventHandler{
	
	private Context mContext;
	private Button titleLeftBtn,titleRightBtn;	
	private TextView titleText;	
	private ListView listview;
	private LinearLayout noticeLayout;
	private List<Map<String, Object>> listData;
	private Intent intent;
	private String value;
	private List<CommentItem> msgList = new ArrayList<CommentItem>();// 消息对象数组
	private CommentMsgDB commentMsgDB;
    private CommentAdapter adapter;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.chat_notice);
		mContext = this;
		intent=getIntent();
		value=intent.getStringExtra("text");
		commentMsgDB = HSApplication.getInstance().getCommentMsgDB();
		initCommentMsgData();
		
		findView();
		listView();
	}
	
	/**
	 * 从数据库中读出与我相关的评论历史数据
	 */
	public void initCommentMsgData() {
		List<CommentItem> list = commentMsgDB.getCommentMsgList();  //getMsg(mFromUser.getUserId(),MsgPagerNum);
		if (list.size() > 0) {
			for (CommentItem entity : list) {

				msgList.add(entity);
			}
		}

	}
	
	
	private void findView() {
		titleLeftBtn = (Button)findViewById(R.id.layout_title_left_btn);
		titleRightBtn= (Button)findViewById(R.id.layout_title_right_btn);
		titleText=(TextView)findViewById(R.id.layout_title_middle_text);
		listview=(ListView)findViewById(R.id.chat_notice_listview);
		noticeLayout=(LinearLayout)findViewById(R.id.chat_notice_none_layout);
		
		initView();
	}

	public void initView(){
		titleLeftBtn.setText("返回");
		titleText.setText(value);
		titleRightBtn.setVisibility(View.INVISIBLE);
		titleLeftBtn.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Item07View.my_adapter.notifyDataSetChanged();
				finish();
			}
		});
	}
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		
		if(keyCode== event.KEYCODE_BACK){
			Item07View.my_adapter.notifyDataSetChanged();
			finish();			
		}
		return true;
	}
	private void listView(){
		getNoticeData();
		adapter = new CommentAdapter(mContext, noticeLayout, msgList);
		listview.setAdapter(adapter);
		
	}

	/**
	 * 获得评论的数据
	 */
	private void getNoticeData() {
		listData=new ArrayList<Map<String,Object>>();
		//在这里获得评论的数据，然后添加到listData里面
		//、、、、、、、、、、、、、、、
	}
	
	





	@Override
	public void onMessage(String message) {
		
	}

	@Override
	public void onBind(String method, int errorCode, String content) {
		
	}

	@Override
	public void onNotify(String title, String content) {
		
	}

	@Override
	public void onNetChange(boolean isNetConnected) {
		
	}

	@Override
	protected void onPause() {
		super.onPause();
		PushMessageReceiver.ehList_Comment.remove(this);//移除监听
	}	
	@Override
	protected void onResume() {
		super.onResume();
		PushMessageReceiver.ehList_Comment.add(this);// 监听推送的消息
	}

	

}
